<template >
  <div class="loginMing">
    <el-row>
      <el-col :span="8" :offset="8"
        ><el-card class="loginForm">
          <div slot="header" class="clearfix">
            <span>用户登录</span>
          </div>
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="账号" prop="userName">
              <el-input v-model="ruleForm.userName"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input v-model="ruleForm.password" show-password></el-input>
            </el-form-item>
            <el-form-item label="验证码">
              <el-col :span="12">
                <el-input v-model="ruleForm.validateCode"> </el-input>
              </el-col>
              <el-col :span="8" :offset="2">
                <img
                  src=""
                />
                {{ CodeList }}
              </el-col>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')"
                >登录</el-button
              >
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { GetUser } from "../api/admin";
import { Captcha } from "../api/admin";
export default {
  data() {
    return {
      CodeList:"",
      ruleForm: {
        userName: "",
        password: "",
        validateCode: "",
      },
      rules: {
        userName: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          GetUser(this.ruleForm).then((res) => {
            this.$message({
              message: res.message,
              type: "warning",
            });
            let token = res.token;
            localStorage.setItem("token", token);
            this.$router.push("/HomeView");
          });
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    Code() {
      Captcha(1).then((res) => {
        this.CodeList = res.data;
        console.log(res.data);
      });
    },
  },
  mounted() {},
};
</script>
<style>
.loginMing {
  height: 100%;
  background: url("../assets/ws.jpg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.loginForm {
  margin: 0 auto;
  margin-top: 40em;
}
.demo-ruleForm{
  margin-top: 0em;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
</style>